package com.iwat.hellospringboot.config;

import com.iwat.hellospringboot.service.NotificationService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author 王伟强
 * @date 2024/5/6 16:20
 */

@Component
public class StartupRunner implements ApplicationRunner {
    private NotificationService notificationService;

    public StartupRunner(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

    @Override
    public void run(ApplicationArguments args) {
        while (true){
            try {
                TimeUnit.MILLISECONDS.sleep(2000);
                notificationService.notify("/topic/handle", "Hello, I'm server!");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
